Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dictionary expressions: add resolutions for open questions from LDM-2024-03-11 #8074

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

cston
Copy link
Member

@cston cston commented Apr 24, 2024

No description provided.

@cston cston requested a review from a team as a code owner April 24, 2024 01:26
@cston cston requested a review from CyrusNajmabadi April 24, 2024 01:26
@@ -149,6 +155,7 @@ Which approach should we go with with our dictionary expressions? Options includ
2. Purely permissive. All elements are added using the indexer. Perhaps with compiler warnings if the exact same key is given the same constant value twice.
3. Perhaps a hybrid model. `.Add` if only using `k:v` and switching to indexers if using spread elements. There is deep potential for confusion here.

**Resolution:** Use *indexer* as the lowering form. [LDM-2024-03-11](https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-03-11.md#conclusions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should we handle the contradiction between this and the resolution to open question 3:

Dictionary elements will be supported in collection expressions for collection types that have a key-value pair element type.

Which used this example, for which list["mads"] = 21 will not work:

List<KeyValuePair<string, int>> list = ["mads": 21];

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Added an open question.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

godo question. my preference is '3'. normal pre-dictionary collection initializable types have 'Add' semantics for their elements. I would prefer to stick with that for sanity/consistency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Credit to Fred :)

@cston cston merged commit 9a8e760 into dotnet:main Apr 26, 2024
1 check passed
@cston cston deleted the dictionary-answers branch April 26, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants